<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>做浏览器兼容</title>
	<style type="text/css">
        #div1{
        	width:200px;height:200px;background:blue;
        }
	</style>

	<script type="text/javascript">
        //封装个方法
        function getStyle(obj,name){
            //做个判断，兼容处理
            if(obj.currentStyle){
                return obj.currentStyle[name];
            }else{
                return getComputedStyle(obj,false)[name]; //注意
            }
        }


        window.onload = function (){
        	var oDiv = document.getElementById('div1');           
            alert(getStyle(oDiv,'width'));   //调用

        };


	</script>
</head>

<body>
    
    <div id="div1"></div>
	
</body>
</html>